Skip to content

feat(schema): bounded 32-bit numeric schemas - #934

Merged
omegent-app[bot] merged 3 commits into
mainfrom
schema/numeric-32-bit
Nov 16, 2026
Merged

omegent-app[bot] merged 3 commits into
mainfrom
schema/numeric-32-bit

Conversation

@omegent-app

@omegent-app omegent-app Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

Int, PositiveInt and NonNegativeInt accept the full JavaScript safe-integer range and export type: integer, maximum: 9007199254740991 without a format. OpenAPI Generator's Java client (7.27.0, bean validation) maps them to Integer and emits the unsuffixed literal @Max(9007199254740991), which javac rejects with integer number too large (an L suffix would compile, since @Max.value() is long, but would still advertise a range Integer cannot hold); and the runtime still accepts values a Java Integer consumer cannot represent. There was no bounded alternative for the number family either.

What

Additive 32-bit counterparts for the complete numeric family in effect-app/Schema (existing schemas unchanged):

New Runtime range (decode + encode) JSON Schema / OpenAPI Default Brand extends
Int32 integer [-2147483648, 2147483647] integer, min/max, format: int32 0 Int
NonNegativeInt32 integer [0, 2147483647] integer, minimum: 0, max, int32 0 Int32, NonNegativeInt, NonNegativeNumber32
PositiveInt32 integer [1, 2147483647] integer, minimum: 1, max, int32 1 NonNegativeInt32, PositiveInt, PositiveNumber32
NonNegativeNumber32 finite [0, 3.4028235e38] number, min/max, format: float 0 NonNegativeNumber
PositiveNumber32 finite [1.4e-45, 3.4028235e38] number, min/max, float 1 NonNegativeNumber32, PositiveNumber

Also exported: INT32_MIN, INT32_MAX, FLOAT32_MIN_POSITIVE = 1.4e-45 and FLOAT32_MAX = 3.4028235e38: the literals Java writes for Float.MIN_VALUE / Float.MAX_VALUE, so the server accepts Java's own extremes. They round to the exact binary32 extremes 2^-149 and (2-2^-23)*2^127.

The deprecated PositiveDecimal / NonNegativeDecimal aliases get no 32-bit counterpart: they are deprecated aliases of the Number schemas, so the Number32 schemas cover them.

flattenSimpleAllOf now intersects repeated bounds and keeps the allOf on other conflicting validation keywords. Before, the last allOf member overwrote the parent, e.g. S.Number.check(S.isInt32(), S.isGreaterThanOrEqualTo(0)) exported minimum: -2147483648.

How

  • Integers: S.Int + the existing lower-bound check + isLessThanOrEqualTo(INT32_MAX), whose JSON Schema also carries format: "int32", so Effect inlines it and tightens the safe-integer bounds.
  • Floats: S.Finite + the lower-bound check + isLessThanOrEqualTo(FLOAT32_MAX) with format: "float". These are range checks only: values are not rounded to binary32, and fractions stay as they are. Values above FLOAT32_MAX are rejected, so nothing that overflows to Infinity is accepted. This is conservative: the double-only sliver up to the rounding threshold is also rejected. PositiveNumber32 rejects values below FLOAT32_MIN_POSITIVE, so nothing that underflows to 0 is accepted. NonNegativeNumber32 accepts those tiny values, because underflowing to 0 keeps them non-negative.
  • Same brand, constructor (schema(n)), construction-only withConstructorDefault and Arbitrary conventions as the existing schemas.
  • Tests (numbers32.test.ts): both boundaries and the values just beyond them, zero, negatives, fractions, NaN/Infinity for decode, encode and make; Arbitrary samples; defaults; brand assignability; exact JSON Schema and deduplicated OpenAPI components next to the existing Int/PositiveInt/NonNegativeInt; the flattenSimpleAllOf regression.

Remarks

  • Java check (manual, not in CI): OpenAPI Generator 7.27.0, -g java --library native, useBeanValidation=true,useJakartaEe=true, JDK 21.0.12 mvn compile. The input was an OpenAPI 3.1 doc from OpenApi.fromApi + deduplicateOpenApiSchemas with a Class model using all five new schemas, plus optional, nullable and array-item variants. Result: Integer / Float fields with @Min(-2147483648|0|1) @Max(2147483647) and @DecimalMin("1.4E-45"|"0") @DecimalMax("340282350000000000000000000000000000000"); compiled. Control: the same doc with the existing PositiveInt/NonNegativeInt fails with integer number too large. Not covered: other generators/libraries and runtime bean validation.
  • PositiveInt32 uses >= 1 instead of > 0 (same integer set) because the generator turns 3.1 exclusiveMinimum: 0 into @Min(0), which would accept 0.
  • Semver minor (additive API); this bumps the fixed effect-app package group.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Add Int32, NonNegativeInt32, PositiveInt32, NonNegativeNumber32 and
PositiveNumber32 with runtime-enforced Java Integer / binary32 ranges and
matching JSON Schema / OpenAPI bounds and formats. Make flattenSimpleAllOf
intersect repeated bounds instead of overwriting them.
@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@effect-app/cli

npm i https://pkg.pr.new/@effect-app/cli@934

effect-app

npm i https://pkg.pr.new/effect-app@934

@effect-app/eslint-codegen-model

npm i https://pkg.pr.new/@effect-app/eslint-codegen-model@934

@effect-app/eslint-shared-config

npm i https://pkg.pr.new/@effect-app/eslint-shared-config@934

@effect-app/infra

npm i https://pkg.pr.new/@effect-app/infra@934

@effect-app/vue

npm i https://pkg.pr.new/@effect-app/vue@934

@effect-app/vue-components

npm i https://pkg.pr.new/@effect-app/vue-components@934

commit: 6075450

@omegent-app
omegent-app Bot marked this pull request as ready for review November 16, 2026 11:05
@omegent-app
omegent-app Bot merged commit b1668a6 into main Nov 16, 2026
5 checks passed
@omegent-app
omegent-app Bot deleted the schema/numeric-32-bit branch November 16, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants